#include "NeoLineEditStyle.h"
#include "stdafx.h"
#include <QPainter>
#include <QStyleOption>

NeoLineEditStyle::NeoLineEditStyle(QStyle *style)
    : QProxyStyle(style) {}

NeoLineEditStyle::~NeoLineEditStyle() = default;

void NeoLineEditStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
    switch (element)
    {
    case PE_PanelLineEdit:
    {
        if (const QStyleOptionFrame *frameOption = qstyleoption_cast<const QStyleOptionFrame *>(option))
        {
            const int borderRadius = 5;
            const int lineRadius = 1;

            QRect adjustedRect = frameOption->rect.adjusted(NEO_RADIUS_ADJUSTED_VALUES);
            painter->save();
            painter->setRenderHint(QPainter::Antialiasing, true);
            painter->setPen(Qt::lightGray);
            painter->drawRoundedRect(adjustedRect, borderRadius, borderRadius);
            if (frameOption->state & QStyle::State_MouseOver)
            {
                painter->setPen(Qt::lightGray);
                painter->setBrush(Qt::lightGray);
                painter->drawRoundedRect(adjustedRect, borderRadius, borderRadius);
            }
            painter->restore();
            if (frameOption->state & QStyle::State_HasFocus)
            {
                painter->save();
                painter->setPen(Qt::blue);
                painter->setBrush(Qt::blue);
                QRect lineRect = adjustedRect.adjusted(2 * lineRadius, adjustedRect.height() - 2 * lineRadius, -2 * lineRadius, 0);
                painter->drawRoundedRect(lineRect, lineRadius, lineRadius);
                painter->restore();
            }
            return;
        }
        break;
    }
    default:
        break;
    }

    return QProxyStyle::drawPrimitive(element, option, painter, widget);
}
